/* 原型模式 */

pub struct User {
    pub name: String,
    pub age: u8,
    pub sex: String
}

impl Clone for User {
    fn clone(&self) -> User {
        User {
            name: self.name.clone(),
            age: self.age,
            sex: self.sex.clone()
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_prototype_1() {
        let user1 = User {
            name: String::from("曹操"),
            age: 46,
            sex: String::from("男")
        };

        let user2 = user1.clone();

        assert_eq!(String::from("曹操"), user1.name);
        assert_eq!(46, user1.age);
        assert_eq!(String::from("男"), user1.sex);

        assert_eq!(String::from("曹操"), user2.name);
        assert_eq!(46, user2.age);
        assert_eq!(String::from("男"), user2.sex);
    }
}